package Ventanas;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JButton;

import ClasesBasicas.Ingrediente;
import ClasesBasicas.PizzaSugerida;
import Gestores.SistemaCliente;
import Gestores.SistemaEmpleado;
import Gestores.SistemaPizzaSugerida;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.sql.SQLException;
import java.util.ArrayList;
import java.awt.Toolkit;

import javax.swing.ImageIcon;

import java.awt.Font;

public class ventanaConsultarVotosPizzas extends JFrame {

	private JPanel contentPane;
	private JTextField ing1textField;
	private JTextField ing2textField;
	private JTextField ing3textField;
	private JComboBox comboBox;
	private JTextField salsatextField;
	private JTextField textFieldpuntos;
	private JTextField textField;
	private JLabel lblCliente;
	private ArrayList<String> sugeridas;
	private JLabel label;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					ventanaConsultarVotosPizzas frame = new ventanaConsultarVotosPizzas();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 * @throws SQLException 
	 * @throws ClassNotFoundException 
	 */
	public ventanaConsultarVotosPizzas() throws ClassNotFoundException, SQLException {
		setResizable(false);
		setTitle("Consulta votos pizza");
		setIconImage(Toolkit.getDefaultToolkit().getImage("src\\Fotos\\txoPizzeria.jpg"));
		
	
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 501, 402);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		
		comboBox = new JComboBox();
		
		comboBox.setBounds(200, 32, 134, 20);
		contentPane.add(comboBox);
		SistemaPizzaSugerida sp=new SistemaPizzaSugerida();
		sugeridas=sp.usersList();
		int i=0;
		if(!sugeridas.isEmpty()){
			
			while(i<sugeridas.size()){
				comboBox.addItem(sugeridas.get(i));
				i++;
			}
		}
		
		
		JLabel lblNewLabel = new JLabel("Ingrediente 1:");
		lblNewLabel.setBounds(36, 95, 98, 20);
		contentPane.add(lblNewLabel);
		
		JLabel lblNewLabel_1 = new JLabel("Ingrediente 2:");
		lblNewLabel_1.setBounds(36, 149, 91, 14);
		contentPane.add(lblNewLabel_1);
		
		JLabel lblNewLabel_2 = new JLabel("Ingrediente 3:");
		lblNewLabel_2.setBounds(36, 197, 98, 14);
		contentPane.add(lblNewLabel_2);
		
		ing1textField = new JTextField();
		ing1textField.setEditable(false);
		ing1textField.setBounds(144, 95, 134, 20);
		contentPane.add(ing1textField);
		ing1textField.setColumns(10);
		
		
		ing2textField = new JTextField();
		ing2textField.setEditable(false);
		ing2textField.setBounds(144, 146, 134, 20);
		contentPane.add(ing2textField);
		ing2textField.setColumns(10);
		
		ing3textField = new JTextField();
		ing3textField.setEditable(false);
		ing3textField.setBounds(144, 194, 133, 20);
		contentPane.add(ing3textField);
		ing3textField.setColumns(10);
		
		comboBox.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {

					SistemaPizzaSugerida sp=new SistemaPizzaSugerida();
					PizzaSugerida p;
					try {
						p = sp.buscarPizza(comboBox.getSelectedItem().toString());
						Ingrediente [] ing=p.getaIngredientes();
						ing1textField.setText(ing[0].getIngrediente());
						ing2textField.setText(ing[1].getIngrediente());
						ing3textField.setText(ing[2].getIngrediente());
						salsatextField.setText(p.getSalsa());
						textFieldpuntos.setText(Integer.toString(p.getPuntos()));
						SistemaCliente sc=new SistemaCliente();
						String nick=sc.obtenerNick(p.getCliente());
						textField.setText(nick);
						
						
						
					} catch (ClassNotFoundException | SQLException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					
					
				}
				
			
		});
		
		
		
		
		JButton btnVolver = new JButton("Volver");
		btnVolver.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				setVisible(false);
				ventanaAdminLogeado v=new ventanaAdminLogeado();
				v.setLocationRelativeTo(null);
				v.setVisible(true);
			}
		});
		btnVolver.setBounds(10, 11, 74, 23);
		contentPane.add(btnVolver);
		
		JLabel lblSalsa = new JLabel("Salsa:");
		lblSalsa.setBounds(36, 238, 46, 14);
		contentPane.add(lblSalsa);
		
		salsatextField = new JTextField();
		salsatextField.setEditable(false);
		salsatextField.setBounds(144, 235, 134, 20);
		contentPane.add(salsatextField);
		salsatextField.setColumns(10);
		
		JLabel lblPuntos = new JLabel("Puntos: ");
		lblPuntos.setBounds(36, 281, 96, 14);
		contentPane.add(lblPuntos);
		
		textFieldpuntos = new JTextField();
		textFieldpuntos.setEditable(false);
		textFieldpuntos.setBounds(144, 278, 134, 20);
		contentPane.add(textFieldpuntos);
		textFieldpuntos.setColumns(10);
		
		textField = new JTextField();
		textField.setEditable(false);
		textField.setBounds(144, 320, 134, 20);
		contentPane.add(textField);
		textField.setColumns(10);
		
		lblCliente = new JLabel("Creador: ");
		lblCliente.setBounds(36, 323, 91, 14);
		contentPane.add(lblCliente);
		
		JButton btnNewButton = new JButton("Borrar pizza sugerida\r\n");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				setVisible(false);
				ventanaBorrarSugerida v;
				try {
					v = new ventanaBorrarSugerida();
					v.setLocationRelativeTo(null);
					v.setVisible(true);
				} catch (ClassNotFoundException | SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				
			}
		});
		btnNewButton.setFont(new Font("Tahoma", Font.BOLD, 11));
		btnNewButton.setBounds(297, 291, 188, 49);
		contentPane.add(btnNewButton);
		
		JButton btnGraficaSugeridas = new JButton("Grafica pizzas sugeridas\r\n");
		btnGraficaSugeridas.setFont(new Font("Tahoma", Font.BOLD, 11));
		btnGraficaSugeridas.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				
			}
		});
		btnGraficaSugeridas.setBounds(297, 208, 188, 49);
		contentPane.add(btnGraficaSugeridas);
		
		label = new JLabel("");
		label.setIcon(new ImageIcon("src\\Fotos\\fondo-textured-blanco-y-azul-abstracto-5013168.jpg"));
		label.setBounds(0, 0, 495, 373);
		contentPane.add(label);
		
		
	}
}
